public class Text1 {
    //快慢指针判断环的入口
    public ListNode EntryNodeOfLoop(ListNode head) {
        if(head == null){
            return null;
        }

        ListNode slow = head;
        ListNode fast = head;


        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;

            if(slow == fast){
                break;
            }
        }

        if(fast == null || fast.next == null){
            return null;
        }

        // 头结点A -X- 环入口结点B -Y- 相遇结点C
        // slow 走的举例为 X+Y     fast 走的举例为 2*（X+Y）
        // BC举例为 Y             fast 走的举例路程为：A-B-C-B-C
        // C-B的距离为X
        fast = head;
        while(fast != slow){
            fast = fast.next;
            slow = slow.next;
        }
        return fast;
    }
}
